import requests
import time


def get_csdn_hot():
    news_ls = []
    for i in range(2):
        url = "https://blog.csdn.net/phoenix/web/blog/hot-rank?page=" + str(i) + "&pageSize=50"
        # print(url)
        # csdn做了校验，必须设置请求头中的User-Agent才能成功返回内容
        headers = {
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"}
        resp = requests.get(url, headers=headers)
        resp = resp.json()
        news = resp['data']
        for new in news:
            news_ls.append({"title": new.get('articleTitle'), "url": new.get('articleDetailUrl')})
    news_ls.reverse()
    return news_ls
